import { Observable } from 'rxjs/Observable';
import { environment } from '../../environments/environment';
// 在module中定义 debug 方法
declare module 'rxjs/Observable' {
    // tslint:disable-next-line:no-shadowed-variable
    interface Observable<T> {
        debug: (...any) => Observable<T>;
    }
}

// 因为do 没有区别 开发模式还是生产模式 重写do方法
Observable.prototype.debug = function (message: string) {
    return this.do(
        (next) => {
            if (!environment.production) {
                console.log(message, next);
            }
        },
        (err) => {
            if (!environment.production) {
                console.error('ERROR>>', message, err);
            }
        },
        () => {
            if (!environment.production) {
                console.log(message + 'completed - ');
            }
        }
    );
};
